﻿<Window
    x:Class="Markup.Programming.Samples.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="http://markupprogramming.codeplex.com/markup/programming"
    xmlns:samples="clr-namespace:Markup.Programming.Samples"
    xmlns:om2b="clr-namespace:Markup.Programming.Samples.OneMethodTwoBindings"
    Width="500" Height="500">
    <Window.Resources>
        <p:ResourceCollection x:Key="Windows">
            <samples:GraphicalSample/>
            <samples:TableOfSquares/>
            <samples:SelectOnFocusComboBox/>
            <samples:StyleSample/>
            <samples:LogoSample/>
            <samples:DraggablePopup/>
            <om2b:View/>
        </p:ResourceCollection>
        <p:ResourceObject x:Key="ViewModel">
            <p:Property PropertyName="Samples">
                <p:Iterator>
                    <p:ForEach Var="$window" Value="{StaticResource Windows}">
                        <p:Yield>
                            <p:Object>
                                <p:Property PropertyName="Name" Path="$window.ToString()"/>
                                <p:Property PropertyName="Control" Path="$window"/>
                            </p:Object>
                        </p:Yield>
                    </p:ForEach>
                </p:Iterator>
            </p:Property>
        </p:ResourceObject>
    </Window.Resources>
    <Grid DataContext="{Binding Value, Source={StaticResource ViewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Text="Markup Programming WPF Samples" FontSize="20"/>
        <ComboBox ItemsSource="{Binding Samples}" Grid.Row="1">
            <p:Attached.Operations>
                <p:ScriptHandler Path="SelectionChanged">
                    var $children = @FindElement("ContentHost").Children;
                    $children.Clear();
                    $children.Add(Samples[@AssociatedObject.SelectedIndex].Control);
                </p:ScriptHandler>
            </p:Attached.Operations>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <Grid Name="ContentHost" Grid.Row="2" Background="SlateGray"/>
    </Grid>
</Window>
